import request from "@/common/utils/request";

  // 文字转语音, 获取积分
export const storyConfigGet = (data = {}) => {
  const { number = null } = data;
  return new Promise(async (resolve, reject) => {
    const res = await request.get(
      "/work_ai",
      "/user/shotstack/point/story/get",
      {
        number,
      }
    );
    if (res?.usable != 1) {
      // 充值打开弹窗
      reject(res);
      return;
    }
    resolve(res);
  });
};

  // 文字转语音, 获取积分
export const textConfigGet = (data={}) => {
   const { number = null } = data;
  return new Promise(async (resolve, reject) => {
    const res = await request.get(
      "/work_ai",
      "/user/shotstack/text_to_speech/config/get",
      {
        number,
      }
    );
    if (res?.usable != 1) {
      // 充值打开弹窗
      reject(res)
      return
    }
    resolve(res)
  })
}

// ai生文积分消耗接口
export const aiTextGet = (data = {}) => {
  const { number = 10 } = data;
  return new Promise(async (resolve, reject) => {
    const res = await request.get(
      "/work_ai",
      "/user/shotstack/point/aiText/get",
      {
        number,
      }
    );
    console.log(res, "ai生文的积分消耗");
    if (res?.usable != 1) {
      // 充值打开弹窗
      reject(false);
      return;
    }
    resolve(res);
  });
};

// 数字人生成视频 number时间传的是秒
export const humanConfigGet = (data = {}) => {
  const { number = null } = data;
  return new Promise(async (resolve, reject) => {
    const res = await request.get("/work_ai", "/digital/human/config/get", {
      number,
    });
    console.log(res, "数字人生成视频积分");
    if (res?.usable != 1) {
      // 充值打开弹窗
      reject(res);
      return;
    }
    resolve(res);
  });
};

// 获取积分消耗规则
export const consumptionPointRule = () => {
  return new Promise(async (resolve, reject) => {
    try {
      const res = await request.get(
        "/work_ai",
        "/user/consume/consumptionPoint/rule",
        {
          isShotStack: 1,
        }
    );
    resolve(res);
    } catch (error) {
      console.log(error);
      reject(error);
    }
  }) 
}

// 视频提取文案
export const videoConverTextConfig = (data = {}) => {
  const { number = 1 } = data;
  return new Promise(async (resolve, reject) => {
    const res = await request.get(
      "/work_ai",
      "/user/shotstack/video/conver/text/config",
      {
        number,
      }
    );
    console.log(res, "视频提取文案积分");
    if (res?.usable != 1) {
      // 充值打开弹窗
      reject(res);
      return;
    }
    resolve(res);
  });
};

// 一键成片, 预计合成视频数量
export const oneclickPreviewNum = (data = {}) => {
  const { number = 1 } = data;
  return new Promise(async (resolve, reject) => {
    const res = await request.get(
      "/work_ai",
      "/user/shotstack/oneclick/preview/num",
      {
        number,
      }
    );
    console.log(res, "一键成片, 预计合成视频数量");
    if (res?.usable != 1) {
      // 充值打开弹窗
      reject(res);
      return;
    }
    resolve(res);
  });
};